package o;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;
import com.huawei.appgallery.splashscreen.impl.cache.FragmentCacheBean;
import com.huawei.appgallery.splashscreen.impl.cache.ImageCacheBean;
import org.json.JSONException;
import org.json.JSONObject;

public class cyx {
    protected static final SharedPreferences ॱ = cyn.ॱ().getSharedPreferences("StartImageInfo", 0);

    public static int ˏ() {
        return ˎ("startImagecount", 0);
    }

    public static void ˏ(int i) {
        ˊ("startImagecount", i);
    }

    public static void ॱ(cyv o_cyv, int i) {
        String toJson;
        IllegalAccessException e;
        String str = null;
        if (o_cyv != null) {
            try {
                toJson = o_cyv.ॱ().toJson();
                try {
                    str = o_cyv.ˏ().toJson();
                } catch (IllegalAccessException e2) {
                    e = e2;
                    cyq.ˋ.ˊ("SplashScreenSP", "cacheStartImage error: " + e.toString());
                    ˊ("festival_image_info_key" + i, toJson);
                    ˊ("festival_fragment_info_key" + i, str);
                }
            } catch (IllegalAccessException e3) {
                e = e3;
                toJson = str;
                cyq.ˋ.ˊ("SplashScreenSP", "cacheStartImage error: " + e.toString());
                ˊ("festival_image_info_key" + i, toJson);
                ˊ("festival_fragment_info_key" + i, str);
            }
            ˊ("festival_image_info_key" + i, toJson);
            ˊ("festival_fragment_info_key" + i, str);
        }
    }

    public static cyv ॱ(int i) {
        Object ˏ = ˏ("festival_image_info_key" + i, "");
        String ˏ2 = ˏ("festival_fragment_info_key" + i, "");
        if (TextUtils.isEmpty(ˏ)) {
            return null;
        }
        cyv o_cyv = new cyv();
        ImageCacheBean imageCacheBean = new ImageCacheBean();
        FragmentCacheBean fragmentCacheBean = new FragmentCacheBean();
        try {
            imageCacheBean.fromJson(new JSONObject(ˏ));
            fragmentCacheBean.fromJson(new JSONObject(ˏ2));
            o_cyv.ˊ(imageCacheBean);
            o_cyv.ˏ(fragmentCacheBean);
        } catch (IllegalAccessException e) {
            cyq.ˋ.ˊ("SplashScreenSP", "getStartImageCache error: " + e.toString());
            o_cyv = null;
        } catch (InstantiationException e2) {
            cyq.ˋ.ˊ("SplashScreenSP", "getStartImageCache error: " + e2.toString());
            o_cyv = null;
        } catch (ClassNotFoundException e3) {
            cyq.ˋ.ˊ("SplashScreenSP", "getStartImageCache error: " + e3.toString());
            o_cyv = null;
        } catch (JSONException e4) {
            cyq.ˋ.ˊ("SplashScreenSP", "getStartImageCache error: " + e4.toString());
            o_cyv = null;
        }
        return o_cyv;
    }

    public static void ˎ() {
    }

    public static void ˊ() {
        ˊ("startImage_lang_region_key", ʻ());
    }

    public static boolean ˋ() {
        Object ˏ = ˏ("startImage_lang_region_key", "");
        if (!TextUtils.isEmpty(ˏ) && ˏ.equals(ʻ())) {
            return false;
        }
        return true;
    }

    private static String ʻ() {
        String ˎ = cdz.ˎ();
        String ˎ2 = cdn.ˎ();
        Object ॱ = cdn.ॱ();
        String ˏ = cdn.ˏ();
        StringBuilder stringBuilder = new StringBuilder(ˎ);
        stringBuilder.append(ˎ2).append("_");
        if (!TextUtils.isEmpty(ॱ)) {
            stringBuilder.append(ॱ).append("_");
        }
        return stringBuilder.append(ˏ).toString();
    }

    public static long ॱ() {
        return ˊ("image_remaining_time", 0);
    }

    public static void ˊ(long j) {
        ˋ("image_remaining_time", j);
    }

    public static void ʽ() {
        ˋ("image_remaining_time", 0);
    }

    public static int ᐝ() {
        return ˎ("current_item_index", 0);
    }

    public static void ˊ(int i) {
        ˊ("current_item_index", i);
    }

    private static void ˊ(String str, String str2) {
        try {
            Editor edit = ॱ.edit();
            edit.putString(str, str2);
            edit.apply();
        } catch (Exception e) {
            cyq.ˋ.ˊ("SplashScreenSP", "putString error!!key:" + str);
        }
    }

    private static void ˋ(String str, long j) {
        try {
            Editor edit = ॱ.edit();
            edit.putLong(str, j);
            edit.apply();
        } catch (Exception e) {
            cyq.ˋ.ˊ("SplashScreenSP", "putLong error!!key:" + str);
        }
    }

    private static void ˊ(String str, int i) {
        try {
            Editor edit = ॱ.edit();
            edit.putInt(str, i);
            edit.apply();
        } catch (Exception e) {
            cyq.ˋ.ˊ("SplashScreenSP", "putInt error!!key:" + str);
        }
    }

    private static String ˏ(String str, String str2) {
        try {
            str2 = ॱ.getString(str, str2);
        } catch (Exception e) {
            ॱ.edit().remove(str).apply();
        }
        return str2;
    }

    private static long ˊ(String str, long j) {
        try {
            j = ॱ.getLong(str, j);
        } catch (Exception e) {
            ॱ.edit().remove(str).apply();
        }
        return j;
    }

    private static int ˎ(String str, int i) {
        try {
            i = ॱ.getInt(str, i);
        } catch (ClassCastException e) {
            ॱ.edit().remove(str).apply();
        }
        return i;
    }
}
